package yifeng;

public class Utils {
	/**
	 * 用给定的delimiter打印一个数组
	 * @param <T>
	 * @param array
	 * @param delimiter
	 */
	public static <T> void printArray(T[] array, String delimiter){
		StringBuilder sb = new StringBuilder();
		sb.append(array.length).append(": ");
		sb.append('[');
		int i = 0;
		for(; i < array.length - 1; i++){
			sb.append(array[i]).append(delimiter);
		}
		sb.append(array[i]);
		sb.append(']');
		
		System.out.println(sb.toString());
	}
	
	public static <T> void printArray(T[] array){
		printArray(array, " ");
	}
	
	public static void printArray(byte[] array, String delimiter){
		StringBuilder sb = new StringBuilder();
		sb.append(array.length).append(": ");
		sb.append('[');
		int i = 0;
		for(; i < array.length - 1; i++){
			sb.append(array[i]).append(delimiter);
		}
		sb.append(array[i]);
		sb.append(']');
		
		System.out.println(sb.toString());
	}
	
	public static void printArray(byte[] array){
		printArray(array, " ");
	}

}
